<template>
  <div class="login-container">
    <!--    登录-->
    <div class="login-box">
      <!--      头像-->
      <div class="avater">
        <img src="../../assets/imgs/huya.png" alt="">
      </div>
      <!--      表单区域-->
      <!--      <div class="form-box">-->
      <el-form :model="user" :rules="rules" ref="ruleForm" label-width="100px" class="login_form">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="user.username" placeholder="请输入用户名称" prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="user.password" placeholder="请输入登录密码" prefix-icon="el-icon-lock"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="verifyCode">
          <div class="verifyCode_box">
            <el-input v-model="user.verifyCode" placeholder="请输入手机验证码" prefix-icon="el-icon-mobile"
                      class="verifyCode"></el-input>
            <img src="../../assets/imgs/yzm.png" alt="" class="verifyCode_img">
          </div>
        </el-form-item>
        <!--按钮-->
        <el-form-item class="login_btn">
          <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
      <!--      </div>-->
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        username: 'lirenzhi',
        password: '123456',
        verifyCode: ''
      },
      rules: {
        username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
        password: [{required: true, message: '请输入密码', trigger: 'blur'}],
        verifyCode: [{required: true, message: '请输入验证码', trigger: 'blur'}]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$router.replace("/home");
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped lang="less">
.login-container {
  height: 100%;
  background-color: aquamarine;

  .login-box {
    height: 320px;
    width: 450px;
    background-color: #FFFFFF;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    .avater {
      width: 130px;
      height: 130px;
      border: 1px solid #EEEEEE;
      border-radius: 50%;
      padding: 10px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      margin: -65px auto;
      background-color: #FFFFFF;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #EEEEEE;
      }
    }

    .login_form {
      position: absolute;
      bottom: 10px;
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box;

      .login_btn {
        display: flex;
        justify-content: flex-end;
      }

      .verifyCode_box {
        display: flex;

        .verifyCode {
          width: 70%;
          justify-content: left;
        }

        .verifyCode_img {
          width: 30%;
          height: 40px;
          justify-content: flex-end;
        }
      }
    }
  }
}
</style>